home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / doom / quake_ad.zip / HOLOGRAM.ZIP / SOURCE / WEAPONS.QC < prev   
Text File  |  1997-02-16  |  29KB  |  1,406 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9.  
  10. // called by worldspawn
  11. void() W_Precache =
  12. {
  13.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  14.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  15.     precache_sound ("weapons/sgun1.wav");
  16.     precache_sound ("weapons/guncock.wav");    // player shotgun
  17.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  20.     precache_sound ("weapons/spike2.wav");    // super spikes
  21.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  22.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  23.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  24.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  25. };
  26.  
  27. float() crandom =
  28. {
  29.     return 2*(random() - 0.5);
  30. };
  31.  
  32. /*
  33. ================
  34. W_FireAxe
  35. ================
  36. */
  37. void() W_FireAxe =
  38. {
  39.     local    vector    source;
  40.     local    vector    org;
  41.  
  42.     makevectors (self.v_angle);
  43.     source = self.origin + '0 0 16';
  44.     traceline (source, source + v_forward*64, FALSE, self);
  45.     if (trace_fraction == 1.0)
  46.         return;
  47.     
  48.     org = trace_endpos - v_forward*4;
  49.  
  50.     if (trace_ent.takedamage)
  51.     {
  52.         trace_ent.axhitme = 1;
  53.         SpawnBlood (org, '0 0 0', 20);
  54.         T_Damage (trace_ent, self, self, 20);
  55.     }
  56.     else
  57.     {    // hit wall
  58.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  59.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  60.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  61.         WriteCoord (MSG_BROADCAST, org_x);
  62.         WriteCoord (MSG_BROADCAST, org_y);
  63.         WriteCoord (MSG_BROADCAST, org_z);
  64.     }
  65. };
  66.  
  67.  
  68. //============================================================================
  69.  
  70.  
  71. vector() wall_velocity =
  72. {
  73.     local vector    vel;
  74.     
  75.     vel = normalize (self.velocity);
  76.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  77.     vel = vel + 2*trace_plane_normal;
  78.     vel = vel * 200;
  79.     
  80.     return vel;
  81. };
  82.  
  83.  
  84. /*
  85. ================
  86. SpawnMeatSpray
  87. ================
  88. */
  89. void(vector org, vector vel) SpawnMeatSpray =
  90. {
  91.     local    entity missile, mpuff;
  92.     local    vector    org;
  93.  
  94.     missile = spawn ();
  95.     missile.owner = self;
  96.     missile.movetype = MOVETYPE_BOUNCE;
  97.     missile.solid = SOLID_NOT;
  98.  
  99.     makevectors (self.angles);
  100.  
  101.     missile.velocity = vel;
  102.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  103.  
  104.     missile.avelocity = '3000 1000 2000';
  105.     
  106. // set missile duration
  107.     missile.nextthink = time + 1;
  108.     missile.think = SUB_Remove;
  109.  
  110.     setmodel (missile, "progs/zom_gib.mdl");
  111.     setsize (missile, '0 0 0', '0 0 0');        
  112.     setorigin (missile, org);
  113. };
  114.  
  115. /*
  116. ================
  117. SpawnBlood
  118. ================
  119. */
  120. void(vector org, vector vel, float damage) SpawnBlood =
  121. {
  122.     particle (org, vel*0.1, 73, damage*2);
  123. };
  124.  
  125. /*
  126. ================
  127. spawn_touchblood
  128. ================
  129. */
  130. void(float damage) spawn_touchblood =
  131. {
  132.     local vector    vel;
  133.  
  134.     vel = wall_velocity () * 0.2;
  135.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  136. };
  137.  
  138.  
  139. /*
  140. ================
  141. SpawnChunk
  142. ================
  143. */
  144. void(vector org, vector vel) SpawnChunk =
  145. {
  146.     particle (org, vel*0.02, 0, 10);
  147. };
  148.  
  149. /*
  150. ==============================================================================
  151.  
  152. MULTI-DAMAGE
  153.  
  154. Collects multiple small damages into a single damage
  155.  
  156. ==============================================================================
  157. */
  158.  
  159. entity    multi_ent;
  160. float    multi_damage;
  161.  
  162. void() ClearMultiDamage =
  163. {
  164.     multi_ent = world;
  165.     multi_damage = 0;
  166. };
  167.  
  168. void() ApplyMultiDamage =
  169. {
  170.     if (!multi_ent)
  171.         return;
  172.     T_Damage (multi_ent, self, self, multi_damage);
  173. };
  174.  
  175. void(entity hit, float damage) AddMultiDamage =
  176. {
  177.     if (!hit)
  178.         return;
  179.     
  180.     if (hit != multi_ent)
  181.     {
  182.         ApplyMultiDamage ();
  183.         multi_damage = damage;
  184.         multi_ent = hit;
  185.     }
  186.     else
  187.         multi_damage = multi_damage + damage;
  188. };
  189.  
  190. /*
  191. ==============================================================================
  192.  
  193. BULLETS
  194.  
  195. ==============================================================================
  196. */
  197.  
  198. /*
  199. ================
  200. TraceAttack
  201. ================
  202. */
  203. void(float damage, vector dir) TraceAttack =
  204. {
  205.     local    vector    vel, org;
  206.     
  207.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  208.     vel = vel + 2*trace_plane_normal;
  209.     vel = vel * 200;
  210.  
  211.     org = trace_endpos - dir*4;
  212.  
  213.     if (trace_ent.takedamage)
  214.     {
  215.         SpawnBlood (org, vel*0.2, damage);
  216.         AddMultiDamage (trace_ent, damage);
  217.     }
  218.     else
  219.     {
  220.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  221.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  222.         WriteCoord (MSG_BROADCAST, org_x);
  223.         WriteCoord (MSG_BROADCAST, org_y);
  224.         WriteCoord (MSG_BROADCAST, org_z);
  225.     }
  226. };
  227.  
  228. /*
  229. ================
  230. FireBullets
  231.  
  232. Used by shotgun, super shotgun, and enemy soldier firing
  233. Go to the trouble of combining multiple pellets into a single damage call.
  234. ================
  235. */
  236. void(float shotcount, vector dir, vector spread) FireBullets =
  237. {
  238.     local    vector direction;
  239.     local    vector    src;
  240.     
  241.     makevectors(self.v_angle);
  242.  
  243.     src = self.origin + v_forward*10;
  244.     src_z = self.absmin_z + self.size_z * 0.7;
  245.  
  246.     ClearMultiDamage ();
  247.     while (shotcount > 0)
  248.     {
  249.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  250.  
  251.         traceline (src, src + direction*2048, FALSE, self);
  252.         if (trace_fraction != 1.0)
  253.             TraceAttack (4, direction);
  254.  
  255.         shotcount = shotcount - 1;
  256.     }
  257.     ApplyMultiDamage ();
  258. };
  259.  
  260. /*
  261. ================
  262. W_FireShotgun
  263. ================
  264. */
  265. void() W_FireShotgun =
  266. {
  267.     local vector dir;
  268.  
  269.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  270.  
  271.     self.punchangle_x = -2;
  272.     
  273.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  274.     dir = aim (self, 100000);
  275.     FireBullets (6, dir, '0.04 0.04 0');
  276. };
  277.  
  278.  
  279. /*
  280. ================
  281. W_FireSuperShotgun
  282. ================
  283. */
  284. void() W_FireSuperShotgun =
  285. {
  286.     local vector dir;
  287.  
  288.     if (self.currentammo == 1)
  289.     {
  290.         W_FireShotgun ();
  291.         return;
  292.     }
  293.         
  294.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  295.  
  296.     self.punchangle_x = -4;
  297.     
  298.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  299.     dir = aim (self, 100000);
  300.     FireBullets (14, dir, '0.14 0.08 0');
  301. };
  302.  
  303.  
  304. /*
  305. ==============================================================================
  306.  
  307. ROCKETS
  308.  
  309. ==============================================================================
  310. */
  311.  
  312. void()    s_explode1    =    [0,        s_explode2] {};
  313. void()    s_explode2    =    [1,        s_explode3] {};
  314. void()    s_explode3    =    [2,        s_explode4] {};
  315. void()    s_explode4    =    [3,        s_explode5] {};
  316. void()    s_explode5    =    [4,        s_explode6] {};
  317. void()    s_explode6    =    [5,        SUB_Remove] {};
  318.  
  319. void() BecomeExplosion =
  320. {
  321.     self.movetype = MOVETYPE_NOCLIP;
  322.     self.velocity = '0 0 0';
  323.     if (self.classname != "holo")
  324.         self.touch = SUB_Null;
  325.     setmodel (self, "progs/s_explod.spr");
  326.     self.solid = SOLID_NOT;
  327.     s_explode1 ();
  328. };
  329.  
  330. void() T_MissileTouch =
  331. {
  332.     local float    damg;
  333.  
  334.     if (other == self.owner)
  335.         return;        // don't explode on owner
  336.  
  337.     if (pointcontents(self.origin) == CONTENT_SKY)
  338.     {
  339.         remove(self);
  340.         return;
  341.     }
  342.  
  343.     damg = 100 + random()*20;
  344.     
  345.     if (other.health)
  346.     {
  347.         if (other.classname == "monster_shambler")
  348.             damg = damg * 0.5;    // mostly immune
  349.         T_Damage (other, self, self.owner, damg );
  350.     }
  351.  
  352.     // don't do radius damage to the other, because all the damage
  353.     // was done in the impact
  354.     T_RadiusDamage (self, self.owner, 120, other);
  355.  
  356. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  357.     self.origin = self.origin - 8*normalize(self.velocity);
  358.  
  359.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  360.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  361.     WriteCoord (MSG_BROADCAST, self.origin_x);
  362.     WriteCoord (MSG_BROADCAST, self.origin_y);
  363.     WriteCoord (MSG_BROADCAST, self.origin_z);
  364.  
  365.     BecomeExplosion ();
  366. };
  367.  
  368.  
  369.  
  370. /*
  371. ================
  372. W_FireRocket
  373. ================
  374. */
  375. void() W_FireRocket =
  376. {
  377.     local    entity missile, mpuff;
  378.     
  379.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  380.     
  381.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  382.  
  383.     self.punchangle_x = -2;
  384.  
  385.     missile = spawn ();
  386.     missile.owner = self;
  387.     missile.movetype = MOVETYPE_FLYMISSILE;
  388.     missile.solid = SOLID_BBOX;
  389.     missile.classname = "missile";
  390.         
  391. // set missile speed    
  392.  
  393.     makevectors (self.v_angle);
  394.     missile.velocity = aim(self, 1000);
  395.     missile.velocity = missile.velocity * 1000;
  396.     missile.angles = vectoangles(missile.velocity);
  397.     
  398.     missile.touch = T_MissileTouch;
  399.     
  400. // set missile duration
  401.     missile.nextthink = time + 5;
  402.     missile.think = SUB_Remove;
  403.  
  404.     setmodel (missile, "progs/missile.mdl");
  405.     setsize (missile, '0 0 0', '0 0 0');        
  406.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  407. };
  408.  
  409. /*
  410. ===============================================================================
  411.  
  412. LIGHTNING
  413.  
  414. ===============================================================================
  415. */
  416.  
  417. /*
  418. =================
  419. LightningDamage
  420. =================
  421. */
  422. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  423. {
  424.     local entity        e1, e2;
  425.     local vector        f;
  426.     
  427.     f = p2 - p1;
  428.     normalize (f);
  429.     f_x = 0 - f_y;
  430.     f_y = f_x;
  431.     f_z = 0;
  432.     f = f*16;
  433.  
  434.     e1 = e2 = world;
  435.  
  436.     traceline (p1, p2, FALSE, self);
  437.     if (trace_ent.takedamage)
  438.     {
  439.         particle (trace_endpos, '0 0 100', 225, damage*4);
  440.         T_Damage (trace_ent, from, from, damage);
  441.         if (self.classname == "player")
  442.         {
  443.             if (other.classname == "player")
  444.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  445.         }
  446.     }
  447.     e1 = trace_ent;
  448.  
  449.     traceline (p1 + f, p2 + f, FALSE, self);
  450.     if (trace_ent != e1 && trace_ent.takedamage)
  451.     {
  452.         particle (trace_endpos, '0 0 100', 225, damage*4);
  453.         T_Damage (trace_ent, from, from, damage);
  454.     }
  455.     e2 = trace_ent;
  456.  
  457.     traceline (p1 - f, p2 - f, FALSE, self);
  458.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  459.     {
  460.         particle (trace_endpos, '0 0 100', 225, damage*4);
  461.         T_Damage (trace_ent, from, from, damage);
  462.     }
  463. };
  464.  
  465.  
  466. void() W_FireLightning =
  467. {
  468.     local    vector        org;
  469.     local    float        cells;
  470.  
  471.     if (self.ammo_cells < 1)
  472.     {
  473.         self.weapon = W_BestWeapon ();
  474.         W_SetCurrentAmmo ();
  475.         return;
  476.     }
  477.  
  478. // explode if under water
  479.     if (self.waterlevel > 1)
  480.     {
  481.         cells = self.ammo_cells;
  482.         self.ammo_cells = 0;
  483.         W_SetCurrentAmmo ();
  484.         T_RadiusDamage (self, self, 35*cells, world);
  485.         return;
  486.     }
  487.  
  488.     if (self.t_width < time)
  489.     {
  490.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  491.         self.t_width = time + 0.6;
  492.     }
  493.     self.punchangle_x = -2;
  494.  
  495.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  496.  
  497.     org = self.origin + '0 0 16';
  498.     
  499.     traceline (org, org + v_forward*600, TRUE, self);
  500.  
  501.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  502.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  503.     WriteEntity (MSG_BROADCAST, self);
  504.     WriteCoord (MSG_BROADCAST, org_x);
  505.     WriteCoord (MSG_BROADCAST, org_y);
  506.     WriteCoord (MSG_BROADCAST, org_z);
  507.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  508.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  509.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  510.  
  511.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  512. };
  513.  
  514.  
  515. //=============================================================================
  516.  
  517.  
  518. void() GrenadeExplode =
  519. {
  520.     T_RadiusDamage (self, self.owner, 120, world);
  521.  
  522.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  523.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  524.     WriteCoord (MSG_BROADCAST, self.origin_x);
  525.     WriteCoord (MSG_BROADCAST, self.origin_y);
  526.     WriteCoord (MSG_BROADCAST, self.origin_z);
  527.  
  528.     BecomeExplosion ();
  529. };
  530.  
  531. void() GrenadeTouch =
  532. {
  533.     if (other == self.owner)
  534.         return;        // don't explode on owner
  535.     if (other.takedamage == DAMAGE_AIM)
  536.     {
  537.         GrenadeExplode();
  538.         return;
  539.     }
  540.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  541.     if (self.velocity == '0 0 0')
  542.         self.avelocity = '0 0 0';
  543. };
  544.  
  545. /*
  546. ================
  547. W_FireGrenade
  548. ================
  549. */
  550. void() W_FireGrenade =
  551. {
  552.     local    entity missile, mpuff;
  553.     
  554.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  555.     
  556.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  557.  
  558.     self.punchangle_x = -2;
  559.  
  560.     missile = spawn ();
  561.     missile.owner = self;
  562.     missile.movetype = MOVETYPE_BOUNCE;
  563.     missile.solid = SOLID_BBOX;
  564.     missile.classname = "grenade";
  565.         
  566. // set missile speed    
  567.  
  568.     makevectors (self.v_angle);
  569.  
  570.     if (self.v_angle_x)
  571.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  572.     else
  573.     {
  574.         missile.velocity = aim(self, 10000);
  575.         missile.velocity = missile.velocity * 600;
  576.         missile.velocity_z = 200;
  577.     }
  578.  
  579.     missile.avelocity = '300 300 300';
  580.  
  581.     missile.angles = vectoangles(missile.velocity);
  582.     
  583.     missile.touch = GrenadeTouch;
  584.     
  585. // set missile duration
  586.     missile.nextthink = time + 2.5;
  587.     missile.think = GrenadeExplode;
  588.  
  589.     setmodel (missile, "progs/grenade.mdl");
  590.     setsize (missile, '0 0 0', '0 0 0');        
  591.     setorigin (missile, self.origin);
  592. };
  593.  
  594.  
  595. //=============================================================================
  596.  
  597. void() spike_touch;
  598. void() superspike_touch;
  599.  
  600.  
  601. /*
  602. ===============
  603. launch_spike
  604.  
  605. Used for both the player and the ogre
  606. ===============
  607. */
  608. void(vector org, vector dir) launch_spike =
  609. {
  610.     newmis = spawn ();
  611.     newmis.owner = self;
  612.     newmis.movetype = MOVETYPE_FLYMISSILE;
  613.     newmis.solid = SOLID_BBOX;
  614.  
  615.     newmis.angles = vectoangles(dir);
  616.     
  617.     newmis.touch = spike_touch;
  618.     newmis.classname = "spike";
  619.     newmis.think = SUB_Remove;
  620.     newmis.nextthink = time + 6;
  621.     setmodel (newmis, "progs/spike.mdl");
  622.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  623.     setorigin (newmis, org);
  624.  
  625.     newmis.velocity = dir * 1000;
  626. };
  627.  
  628. void() W_FireSuperSpikes =
  629. {
  630.     local vector    dir;
  631.     local entity    old;
  632.     
  633.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  634.     self.attack_finished = time + 0.2;
  635.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  636.     dir = aim (self, 1000);
  637.     launch_spike (self.origin + '0 0 16', dir);
  638.     newmis.touch = superspike_touch;
  639.     setmodel (newmis, "progs/s_spike.mdl");
  640.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  641.     self.punchangle_x = -2;
  642. };
  643.  
  644. void(float ox) W_FireSpikes =
  645. {
  646.     local vector    dir;
  647.     local entity    old;
  648.     
  649.     makevectors (self.v_angle);
  650.     
  651.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  652.     {
  653.         W_FireSuperSpikes ();
  654.         return;
  655.     }
  656.  
  657.     if (self.ammo_nails < 1)
  658.     {
  659.         self.weapon = W_BestWeapon ();
  660.         W_SetCurrentAmmo ();
  661.         return;
  662.     }
  663.  
  664.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  665.     self.attack_finished = time + 0.2;
  666.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  667.     dir = aim (self, 1000);
  668.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  669.  
  670.     self.punchangle_x = -2;
  671. };
  672.  
  673.  
  674.  
  675. .float hit_z;
  676. void() spike_touch =
  677. {
  678. local float rand;
  679.     if (other == self.owner)
  680.         return;
  681.  
  682.     if (other.solid == SOLID_TRIGGER)
  683.         return;    // trigger field, do nothing
  684.  
  685.     if (pointcontents(self.origin) == CONTENT_SKY)
  686.     {
  687.         remove(self);
  688.         return;
  689.     }
  690.     
  691. // hit something that bleeds
  692.     if (other.takedamage)
  693.     {
  694.         spawn_touchblood (9);
  695.         T_Damage (other, self, self.owner, 9);
  696.     }
  697.     else
  698.     {
  699.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  700.         
  701.         if (self.classname == "wizspike")
  702.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  703.         else if (self.classname == "knightspike")
  704.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  705.         else
  706.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  707.         WriteCoord (MSG_BROADCAST, self.origin_x);
  708.         WriteCoord (MSG_BROADCAST, self.origin_y);
  709.         WriteCoord (MSG_BROADCAST, self.origin_z);
  710.     }
  711.  
  712.     remove(self);
  713.  
  714. };
  715.  
  716. void() superspike_touch =
  717. {
  718. local float rand;
  719.     if (other == self.owner)
  720.         return;
  721.  
  722.     if (other.solid == SOLID_TRIGGER)
  723.         return;    // trigger field, do nothing
  724.  
  725.     if (pointcontents(self.origin) == CONTENT_SKY)
  726.     {
  727.         remove(self);
  728.         return;
  729.     }
  730.     
  731. // hit something that bleeds
  732.     if (other.takedamage)
  733.     {
  734.         spawn_touchblood (18);
  735.         T_Damage (other, self, self.owner, 18);
  736.     }
  737.     else
  738.     {
  739.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  740.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  741.         WriteCoord (MSG_BROADCAST, self.origin_x);
  742.         WriteCoord (MSG_BROADCAST, self.origin_y);
  743.         WriteCoord (MSG_BROADCAST, self.origin_z);
  744.     }
  745.  
  746.     remove(self);
  747.  
  748. };
  749.  
  750.  
  751. /*
  752. ===============================================================================
  753.  
  754. PLAYER WEAPON USE
  755.  
  756. ===============================================================================
  757. */
  758.  
  759. void() W_SetCurrentAmmo =
  760. {
  761.     player_run ();        // get out of any weapon firing states
  762.  
  763.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  764.     
  765.     if (self.weapon == IT_AXE)
  766.     {
  767.         self.currentammo = 0;
  768.         self.weaponmodel = "progs/v_axe.mdl";
  769.         self.weaponframe = 0;
  770.     }
  771.     else if (self.weapon == IT_SHOTGUN)
  772.     {
  773.         self.currentammo = self.ammo_shells;
  774.         self.weaponmodel = "progs/v_shot.mdl";
  775.         self.weaponframe = 0;
  776.         self.items = self.items | IT_SHELLS;
  777.     }
  778.     else if (self.weapon == IT_SUPER_SHOTGUN)
  779.     {
  780.         self.currentammo = self.ammo_shells;
  781.         self.weaponmodel = "progs/v_shot2.mdl";
  782.         self.weaponframe = 0;
  783.         self.items = self.items | IT_SHELLS;
  784.     }
  785.     else if (self.weapon == IT_NAILGUN)
  786.     {
  787.         self.currentammo = self.ammo_nails;
  788.         self.weaponmodel = "progs/v_nail.mdl";
  789.         self.weaponframe = 0;
  790.         self.items = self.items | IT_NAILS;
  791.     }
  792.     else if (self.weapon == IT_SUPER_NAILGUN)
  793.     {
  794.         self.currentammo = self.ammo_nails;
  795.         self.weaponmodel = "progs/v_nail2.mdl";
  796.         self.weaponframe = 0;
  797.         self.items = self.items | IT_NAILS;
  798.     }
  799.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  800.     {
  801.         self.currentammo = self.ammo_rockets;
  802.         self.weaponmodel = "progs/v_rock.mdl";
  803.         self.weaponframe = 0;
  804.         self.items = self.items | IT_ROCKETS;
  805.     }
  806.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  807.     {
  808.         self.currentammo = self.ammo_rockets;
  809.         self.weaponmodel = "progs/v_rock2.mdl";
  810.         self.weaponframe = 0;
  811.         self.items = self.items | IT_ROCKETS;
  812.     }
  813.     else if (self.weapon == IT_LIGHTNING)
  814.     {
  815.         self.currentammo = self.ammo_cells;
  816.         self.weaponmodel = "progs/v_light.mdl";
  817.         self.weaponframe = 0;
  818.         self.items = self.items | IT_CELLS;
  819.     }
  820.     else
  821.     {
  822.         self.currentammo = 0;
  823.         self.weaponmodel = "";
  824.         self.weaponframe = 0;
  825.     }
  826. };
  827.  
  828. float() W_BestWeapon =
  829. {
  830.     local    float    it;
  831.     
  832.     it = self.items;
  833.  
  834.     if (self.waterlevel <= 1 && self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  835.             return IT_LIGHTNING;
  836.     if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  837.         return IT_SUPER_NAILGUN;
  838.     if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  839.         return IT_SUPER_SHOTGUN;
  840.     if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  841.         return IT_NAILGUN;
  842.     if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  843.         return IT_SHOTGUN;
  844.     return IT_AXE;
  845. };
  846.  
  847. float() W_CheckNoAmmo =
  848. {
  849.     if (self.currentammo > 0)
  850.         return TRUE;
  851.  
  852.     if (self.weapon == IT_AXE)
  853.         return TRUE;
  854.     
  855.     self.weapon = W_BestWeapon ();
  856.  
  857.     W_SetCurrentAmmo ();
  858.     
  859. // drop the weapon down
  860.     return FALSE;
  861. };
  862.  
  863. /*
  864. ============
  865. W_Attack
  866.  
  867. An attack impulse can be triggered now
  868. ============
  869. */
  870. void()    player_axe1;
  871. void()    player_axeb1;
  872. void()    player_axec1;
  873. void()    player_axed1;
  874. void()    player_shot1;
  875. void()    player_nail1;
  876. void()    player_light1;
  877. void()    player_rocket1;
  878.  
  879. void() W_Attack =
  880. {
  881.     local    float    r;
  882.  
  883.     if (!W_CheckNoAmmo ())
  884.         return;
  885.  
  886.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  887.     self.show_hostile = time + 1;    // wake monsters up
  888.  
  889.     if (self.weapon == IT_AXE)
  890.     {
  891.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  892.         r = random();
  893.         if (r < 0.25)
  894.             player_axe1 ();
  895.         else if (r<0.5)
  896.             player_axeb1 ();
  897.         else if (r<0.75)
  898.             player_axec1 ();
  899.         else
  900.             player_axed1 ();
  901.         self.attack_finished = time + 0.5;
  902.     }
  903.     else if (self.weapon == IT_SHOTGUN)
  904.     {
  905.         player_shot1 ();
  906.         W_FireShotgun ();
  907.         self.attack_finished = time + 0.5;
  908.     }
  909.     else if (self.weapon == IT_SUPER_SHOTGUN)
  910.     {
  911.         player_shot1 ();
  912.         W_FireSuperShotgun ();
  913.         self.attack_finished = time + 0.7;
  914.     }
  915.     else if (self.weapon == IT_NAILGUN)
  916.     {
  917.         player_nail1 ();
  918.     }
  919.     else if (self.weapon == IT_SUPER_NAILGUN)
  920.     {
  921.         player_nail1 ();
  922.     }
  923.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  924.     {
  925.         player_rocket1();
  926.         W_FireGrenade();
  927.         self.attack_finished = time + 0.6;
  928.     }
  929.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  930.     {
  931.         player_rocket1();
  932.         W_FireRocket();
  933.         self.attack_finished = time + 0.8;
  934.     }
  935.     else if (self.weapon == IT_LIGHTNING)
  936.     {
  937.         player_light1();
  938.         self.attack_finished = time + 0.1;
  939.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  940.     }
  941. };
  942.  
  943. /*
  944. ============
  945. W_ChangeWeapon
  946.  
  947. ============
  948. */
  949. void() W_ChangeWeapon =
  950. {
  951.     local    float    it, am, fl;
  952.     
  953.     it = self.items;
  954.     am = 0;
  955.     
  956.     if (self.impulse == 1)
  957.     {
  958.         fl = IT_AXE;
  959.     }
  960.     else if (self.impulse == 2)
  961.     {
  962.         fl = IT_SHOTGUN;
  963.         if (self.ammo_shells < 1)
  964.             am = 1;
  965.     }
  966.     else if (self.impulse == 3)
  967.     {
  968.         fl = IT_SUPER_SHOTGUN;
  969.         if (self.ammo_shells < 2)
  970.             am = 1;
  971.     }        
  972.     else if (self.impulse == 4)
  973.     {
  974.         fl = IT_NAILGUN;
  975.         if (self.ammo_nails < 1)
  976.             am = 1;
  977.     }
  978.     else if (self.impulse == 5)
  979.     {
  980.         fl = IT_SUPER_NAILGUN;
  981.         if (self.ammo_nails < 2)
  982.             am = 1;
  983.     }
  984.     else if (self.impulse == 6)
  985.     {
  986.         fl = IT_GRENADE_LAUNCHER;
  987.         if (self.ammo_rockets < 1)
  988.             am = 1;
  989.     }
  990.     else if (self.impulse == 7)
  991.     {
  992.         fl = IT_ROCKET_LAUNCHER;
  993.         if (self.ammo_rockets < 1)
  994.             am = 1;
  995.     }
  996.     else if (self.impulse == 8)
  997.     {
  998.         fl = IT_LIGHTNING;
  999.         if (self.ammo_cells < 1)
  1000.             am = 1;
  1001.     }
  1002.  
  1003.     self.impulse = 0;
  1004.     
  1005.     if (!(self.items & fl))
  1006.     {    // don't have the weapon or the ammo
  1007.         sprint (self, "no weapon.\n");
  1008.         return;
  1009.     }
  1010.     
  1011.     if (am)
  1012.     {    // don't have the ammo
  1013.         sprint (self, "not enough ammo.\n");
  1014.         return;
  1015.     }
  1016.  
  1017. //
  1018. // set weapon, set ammo
  1019. //
  1020.     self.weapon = fl;        
  1021.     W_SetCurrentAmmo ();
  1022. };
  1023.  
  1024. /*
  1025. ============
  1026. CheatCommand
  1027. ============
  1028. */
  1029. void() CheatCommand =
  1030. {
  1031.     if (deathmatch || coop)
  1032.         return;
  1033.  
  1034.     self.ammo_rockets = 100;
  1035.     self.ammo_nails = 200;
  1036.     self.ammo_shells = 100;
  1037.     self.items = self.items | 
  1038.         IT_AXE |
  1039.         IT_SHOTGUN |
  1040.         IT_SUPER_SHOTGUN |
  1041.         IT_NAILGUN |
  1042.         IT_SUPER_NAILGUN |
  1043.         IT_GRENADE_LAUNCHER |
  1044.         IT_ROCKET_LAUNCHER |
  1045.         IT_KEY1 | IT_KEY2;
  1046.  
  1047.     self.ammo_cells = 200;
  1048.     self.items = self.items | IT_LIGHTNING;
  1049.  
  1050.     self.weapon = IT_ROCKET_LAUNCHER;
  1051.     self.impulse = 0;
  1052.     W_SetCurrentAmmo ();
  1053. };
  1054.  
  1055. /*
  1056. ============
  1057. CycleWeaponCommand
  1058.  
  1059. Go to the next weapon with ammo
  1060. ============
  1061. */
  1062. void() CycleWeaponCommand =
  1063. {
  1064.     local    float    it, am;
  1065.     
  1066.     it = self.items;
  1067.     self.impulse = 0;
  1068.     
  1069.     while (1)
  1070.     {
  1071.         am = 0;
  1072.  
  1073.         if (self.weapon == IT_LIGHTNING)
  1074.         {
  1075.             self.weapon = IT_AXE;
  1076.         }
  1077.         else if (self.weapon == IT_AXE)
  1078.         {
  1079.             self.weapon = IT_SHOTGUN;
  1080.             if (self.ammo_shells < 1)
  1081.                 am = 1;
  1082.         }
  1083.         else if (self.weapon == IT_SHOTGUN)
  1084.         {
  1085.             self.weapon = IT_SUPER_SHOTGUN;
  1086.             if (self.ammo_shells < 2)
  1087.                 am = 1;
  1088.         }        
  1089.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1090.         {
  1091.             self.weapon = IT_NAILGUN;
  1092.             if (self.ammo_nails < 1)
  1093.                 am = 1;
  1094.         }
  1095.         else if (self.weapon == IT_NAILGUN)
  1096.         {
  1097.             self.weapon = IT_SUPER_NAILGUN;
  1098.             if (self.ammo_nails < 2)
  1099.                 am = 1;
  1100.         }
  1101.         else if (self.weapon == IT_SUPER_NAILGUN)
  1102.         {
  1103.             self.weapon = IT_GRENADE_LAUNCHER;
  1104.             if (self.ammo_rockets < 1)
  1105.                 am = 1;
  1106.         }
  1107.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1108.         {
  1109.             self.weapon = IT_ROCKET_LAUNCHER;
  1110.             if (self.ammo_rockets < 1)
  1111.                 am = 1;
  1112.         }
  1113.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1114.         {
  1115.             self.weapon = IT_LIGHTNING;
  1116.             if (self.ammo_cells < 1)
  1117.                 am = 1;
  1118.         }
  1119.     
  1120.         if ( (it & self.weapon) && am == 0)
  1121.         {
  1122.             W_SetCurrentAmmo ();
  1123.             return;
  1124.         }
  1125.     }
  1126.  
  1127. };
  1128.  
  1129. /*
  1130. ============
  1131. CycleWeaponReverseCommand
  1132.  
  1133. Go to the prev weapon with ammo
  1134. ============
  1135. */
  1136. void() CycleWeaponReverseCommand =
  1137. {
  1138.     local    float    it, am;
  1139.     
  1140.     it = self.items;
  1141.     self.impulse = 0;
  1142.  
  1143.     while (1)
  1144.     {
  1145.         am = 0;
  1146.  
  1147.         if (self.weapon == IT_LIGHTNING)
  1148.         {
  1149.             self.weapon = IT_ROCKET_LAUNCHER;
  1150.             if (self.ammo_rockets < 1)
  1151.                 am = 1;
  1152.         }
  1153.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1154.         {
  1155.             self.weapon = IT_GRENADE_LAUNCHER;
  1156.             if (self.ammo_rockets < 1)
  1157.                 am = 1;
  1158.         }
  1159.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1160.         {
  1161.             self.weapon = IT_SUPER_NAILGUN;
  1162.             if (self.ammo_nails < 2)
  1163.                 am = 1;
  1164.         }
  1165.         else if (self.weapon == IT_SUPER_NAILGUN)
  1166.         {
  1167.             self.weapon = IT_NAILGUN;
  1168.             if (self.ammo_nails < 1)
  1169.                 am = 1;
  1170.         }
  1171.         else if (self.weapon == IT_NAILGUN)
  1172.         {
  1173.             self.weapon = IT_SUPER_SHOTGUN;
  1174.             if (self.ammo_shells < 2)
  1175.                 am = 1;
  1176.         }        
  1177.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1178.         {
  1179.             self.weapon = IT_SHOTGUN;
  1180.             if (self.ammo_shells < 1)
  1181.                 am = 1;
  1182.         }
  1183.         else if (self.weapon == IT_SHOTGUN)
  1184.         {
  1185.             self.weapon = IT_AXE;
  1186.         }
  1187.         else if (self.weapon == IT_AXE)
  1188.         {
  1189.             self.weapon = IT_LIGHTNING;
  1190.             if (self.ammo_cells < 1)
  1191.                 am = 1;
  1192.         }
  1193.     
  1194.         if ( (it & self.weapon) && am == 0)
  1195.         {
  1196.             W_SetCurrentAmmo ();
  1197.             return;
  1198.         }
  1199.     }
  1200.  
  1201. };
  1202.  
  1203. /*
  1204. ============
  1205. ServerflagsCommand
  1206.  
  1207. Just for development
  1208. ============
  1209. */
  1210. void() ServerflagsCommand =
  1211. {
  1212.     serverflags = serverflags * 2 + 1;
  1213. };
  1214.  
  1215. void() QuadCheat =
  1216. {
  1217.     if (deathmatch || coop)
  1218.         return;
  1219.     self.super_time = 1;
  1220.     self.super_damage_finished = time + 30;
  1221.     self.items = self.items | IT_QUAD;
  1222.     dprint ("quad cheat\n");
  1223. };
  1224.  
  1225. /*
  1226. =============
  1227. HoloGram Code
  1228. =============
  1229. */
  1230.  
  1231. .float    holoon;  // Is the Hologram switched on?
  1232. .entity    hologram; // Hologram on the person
  1233. .float    holodrain; // Drain every 15 test cycles
  1234.  
  1235. void(entity entin) RemoveHolo =
  1236. {
  1237.     self = entin;
  1238.     self.holoon = 0;
  1239.     sprint(self, "Hologram Deactivated\n");
  1240.     remove(self.hologram);
  1241. };
  1242.  
  1243. void() TestHolo =
  1244. {
  1245.     if (self.owner.holodrain == 15)
  1246.     {
  1247.         self.owner.ammo_cells = self.owner.ammo_cells - 1;
  1248.         self.owner.holodrain = 0;
  1249.     }
  1250.  
  1251.     self.owner.holodrain = self.owner.holodrain + 1;
  1252.  
  1253.     self.angles = self.owner.angles;
  1254.     self.nextthink = time + 0.1;
  1255.     self.think = TestHolo;
  1256.  
  1257.     if (self.owner.ammo_cells == 0)
  1258.         RemoveHolo(self.owner);
  1259. };
  1260.  
  1261. void() ToggleHolo =
  1262. {
  1263.     if (self.ammo_cells != 0 && self.holoon != 1)
  1264.         {
  1265.  
  1266.         self.holodrain = 0; // HoloDrain cycle start
  1267.         self.holoon = 1; // Hologram ON
  1268.         // Creates the hologram, assigns values
  1269.         self.hologram = spawn();
  1270.         self.hologram.solid = SOLID_NOT;
  1271.         self.hologram.movetype = MOVETYPE_NOCLIP;
  1272.         self.hologram.origin = self.origin;
  1273.         self.hologram.angles = self.angles;
  1274.         self.hologram.colormap = self.colormap;
  1275.         self.hologram.classname = "holo";
  1276.         self.hologram.owner = self;
  1277.         self.hologram.frame = 13;
  1278.  
  1279.         setmodel (self.hologram, "progs/player.mdl");
  1280.         
  1281.         self.ammo_cells = self.ammo_cells - 1;
  1282.         sprint(self, "Hologram Placed\n"); // Informs the player that he placed a hologram
  1283.  
  1284.         self.hologram.nextthink = time + 0.1;    
  1285.         self.hologram.think = TestHolo;
  1286.     }
  1287.     else if (self.holoon == 1)
  1288.     {
  1289.         self.holoon = 0;
  1290.         RemoveHolo (self);
  1291.     }
  1292.     else if (self.ammo_cells == 0)
  1293.     {
  1294.         sprint(self, "Not enough cells for hologram.\n");
  1295.     }
  1296. };
  1297.  
  1298. void() ExplodeHolo =
  1299. {
  1300.     T_RadiusDamage(self, self, 100, self);
  1301.  
  1302.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  1303.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  1304.     WriteCoord (MSG_BROADCAST, self.origin_x);
  1305.     WriteCoord (MSG_BROADCAST, self.origin_y);
  1306.     WriteCoord (MSG_BROADCAST, self.origin_z);
  1307.  
  1308.     BecomeExplosion();        
  1309. };
  1310.  
  1311. void() PrimeHolo =
  1312. {    
  1313.     if (self.ammo_rockets > 2)
  1314.     {
  1315.     self.ammo_rockets = self.ammo_rockets - 3;    
  1316.     self.holoon = 0;
  1317.     self.impulse = 0;
  1318.  
  1319.     self.hologram.effects = EF_DIMLIGHT;    
  1320.  
  1321.     self = self.hologram;
  1322.  
  1323.     self.nextthink = time + 0.5;
  1324.     self.think = ExplodeHolo;
  1325.     }
  1326.     else sprint(self, "Not enough missile to detonate hologram");
  1327. };
  1328.  
  1329.  
  1330. /*
  1331. ============
  1332. ImpulseCommands
  1333.  
  1334. ============
  1335. */
  1336.  
  1337. void() ImpulseCommands =
  1338. {
  1339.     if (self.impulse >= 1 && self.impulse <= 8)
  1340.         W_ChangeWeapon ();
  1341.  
  1342.     if (self.impulse == 9)
  1343.         CheatCommand ();
  1344.     if (self.impulse == 10)
  1345.         CycleWeaponCommand ();
  1346.     if (self.impulse == 11)
  1347.         ServerflagsCommand ();
  1348.     if (self.impulse == 12)
  1349.         CycleWeaponReverseCommand ();
  1350.  
  1351. // Added the HoloCommand
  1352.     if (self.impulse == 15)
  1353.         ToggleHolo ();
  1354.     if (self.impulse == 20)
  1355.         PrimeHolo ();
  1356.  
  1357.     if (self.impulse == 255)
  1358.         QuadCheat ();
  1359.         
  1360.     self.impulse = 0;
  1361. };
  1362.  
  1363. /*
  1364. ============
  1365. W_WeaponFrame
  1366.  
  1367. Called every frame so impulse events can be handled as well as possible
  1368. ============
  1369. */
  1370. void() W_WeaponFrame =
  1371. {
  1372.     if (time < self.attack_finished)
  1373.         return;
  1374.  
  1375.     ImpulseCommands ();
  1376.     
  1377. // check for attack
  1378.     if (self.button0)
  1379.     {
  1380.         SuperDamageSound ();
  1381.         W_Attack ();
  1382.     }
  1383. };
  1384.  
  1385. /*
  1386. ========
  1387. SuperDamageSound
  1388.  
  1389. Plays sound if needed
  1390. ========
  1391. */
  1392. void() SuperDamageSound =
  1393. {
  1394.     if (self.super_damage_finished > time)
  1395.     {
  1396.         if (self.super_sound < time)
  1397.         {
  1398.             self.super_sound = time + 1;
  1399.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1400.         }
  1401.     }
  1402.     return;
  1403. };
  1404.  
  1405.  
  1406.